package com.hhh.petadopt.serviceImpl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.hhh.petadopt.mapper.RegisterMapper;
import com.hhh.petadopt.pojo.User;
import com.hhh.petadopt.service.RegisterService;
/**
 * 注册处理
 * @author 杜镇声声
 *
 */
@Service
public class RegisterServiceImpl implements RegisterService {

	@Autowired
	private RegisterMapper registermapper;
	
	@Override
	public boolean  selectserByUsername(String username) {
		Integer isExist = 0;
		isExist = registermapper.selectUserByUsername(username);
		return isExist>0?true:false;
	}
	//注册
	@Override
	public void register(User user) {
		//补全信息
		//将密码转换为md5加密
		String password = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
		user.setPassword(password);
		//授权,1代表授权，2代表不授权
		user.setGrantt("1");
		//时间
		user.setCreated(new Date());
		user.setUpdated(new Date());
		
		//执行操作
		registermapper.register(user);
		
	}

}
